home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 08 - 1992 / 08.02 Jun 92 / Modifying Print Dialogs / Dialogs.c next >
Encoding:
C/C++ Source or Header  |  1992-05-26  |  6.7 KB  |  295 lines  |  [TEXT/MPS ]

  1. /*--------------------------------------------
  2. #    MultiFinder-Aware Simple NoDraft Application
  3. #
  4. #    Dialogs.c -    Dialog handling code
  5. #
  6. -------------------------------------------- */
  7.  
  8. #include <Values.h>
  9. #include <Types.h>
  10. #include <Resources.h>
  11. #include <QuickDraw.h>
  12. #include <Fonts.h>
  13. #include <Events.h>
  14. #include <Windows.h>
  15. #include <Menus.h> 
  16. #include <TextEdit.h>
  17. #include <Dialogs.h>
  18. #include <Desk.h>
  19. #include <ToolUtils.h>
  20. #include <Memory.h>
  21. #include <SegLoad.h>
  22. #include <OSUtils.h>
  23. #include <OSEvents.h>
  24. #include <DiskInit.h>
  25. #include <Packages.h>
  26. #include <Controls.h>
  27. #include <Printing.h>
  28. #include <Traps.h>
  29. #include <NoDraft.h>
  30. #include <Nodraft_types.h>
  31.  
  32. pascal TPPrDlg MyJobDlgInit();
  33.  
  34. THPrint        hPrintRec;            
  35.  
  36. /*-------------------------------------------- */
  37.  
  38. void FlashDialogItem(the_dialog, theItem)
  39.  
  40. DialogPtr    the_dialog;
  41. short        theItem;
  42.  
  43.     {
  44.         short        itemType;
  45.         Rect        itemRect;
  46.         Handle        itemHdl;
  47.         long        longdelay, longticks;
  48.         
  49.          GetDItem(the_dialog, theItem, &itemType, &itemHdl, &itemRect); 
  50.     
  51.          if ( itemHdl != nil)  {
  52.                 HiliteControl( (ControlHandle) itemHdl, 1);
  53.                 longdelay = longticks = 6;
  54.                 Delay(longdelay, &longticks);
  55.             }  
  56.         } 
  57.  
  58. /*-------------------------------------------- */
  59.  
  60. void checknetwork()
  61.  
  62.     {
  63.         static int count = 0;    
  64.         /*    I use this routine to check for AppleTalk™
  65.                 messages rather than include all that code,
  66.                 I just beep every once in a while to let 
  67.                 you know it is working, you can change
  68.                 delay_length to increase/decrease
  69.                 freq of Beeps */
  70.     if ( count++ > delay_length ) {
  71.             SysBeep(3);
  72.             count = 0;
  73.             }
  74.     }    /* end of checking the network */
  75.     
  76. /*-------------------------------------------- */
  77.  
  78. pascal Boolean    Net_filter(theDialog, theEvent, itemHit)
  79.  
  80. DialogPtr        theDialog;
  81. EventRecord        *theEvent;
  82. short              *itemHit;
  83.         
  84.     {
  85.             
  86.     int            key;
  87.     Boolean        handled_event;
  88.  
  89.         handled_event = false;    /* did we handle the event */
  90.             
  91.         /* do whatever you have to do for event */
  92.             
  93.         switch  ( theEvent->what) {
  94.             
  95.                 case    nullEvent:
  96.                             checknetwork();
  97.                             break;
  98.                 
  99.                 case    keyDown:
  100.                             key = theEvent->message & charCodeMask;
  101.                             if (( key == cr) || ( key == enter))
  102.                                 {
  103.                                     FlashDialogItem(theDialog, ok); 
  104.                                     *itemHit = ok;
  105.                                     handled_event = true;    /* handled it */
  106.                                 }
  107.                             break;
  108.                 
  109.                 /*    we get all kinds of update events here                 some for our modal dialog and even some
  110.                 for the different windows ( in some cases) 
  111.                 rather than try and process these so that
  112.                 we do get real null events when
  113.                 we can check the network, just check the
  114.                 network and let the update events get
  115.                  processed later */
  116.                             
  117.                             checknetwork();
  118.                             break;
  119.                 
  120.                 case    activateEvt:
  121.                             break;
  122.                 
  123.                 default:
  124.                         /* Don't know what we got here, but */
  125.                         /* but check the network in case we */
  126.                         /* get stuck on this event like we */
  127.                         /* did with updates */
  128.                             
  129.                             checknetwork();
  130.                             break;
  131.             }
  132.         
  133. /* return boolean to tell modal dialog to  */
  134. /* handle the event or not */
  135.         
  136.         return (handled_event);
  137.     }
  138.  
  139. /*-------------------------------------------- */
  140.  
  141. void ShowAboutMeDialog(void)  /* my about… dialog */
  142.     
  143.     {
  144.     short        itemHit;
  145.  
  146.         itemHit = Alert(rAboutAlert, &Net_filter);
  147.  
  148.     } /* ShowAboutMeDialog */
  149.  
  150. /*-------------------------------------------- */
  151.  
  152. void DisableDraftMode(thePrintDialog)
  153.  
  154. TPPrDlg    thePrintDialog;
  155.  
  156. /*  disable the ability to print out draft  */
  157. /*    mode since we can't print our bitmaps */
  158.     
  159.     {
  160.         DialogPeek    theDialogPtr;
  161.         short            i;
  162.         short            num_items;    /* how many in list */
  163.         
  164.         hItemList    hItems;    /* Handle to DLOG’s list  */
  165.  
  166.         short        item_no;
  167.         short        draft_item_no;
  168.         short        better_item_no;
  169.         short        best_item_no;
  170.         short        the_type;    /* vars from GetDitem */
  171.         Handle        the_item;
  172.         Rect        the_box;
  173.         
  174.         char        *the_title = "                       ";
  175.         
  176.         short        the_and_type;
  177.         
  178.         char        *draft_title, *better_title;
  179.         char        *best_title;
  180.         
  181.         Boolean        draft_selected;
  182.         short        draft_value;
  183.     
  184.         /* we are given a DialogPtr which is a ptr */
  185.          /* to the print dialog  */
  186.         /* scan through all the items, and if you  */
  187.          /* get one called draft, disable it */
  188.         
  189.         /* how many items are there to scan */
  190.         
  191.         theDialogPtr = (DialogPeek)thePrintDialog;
  192.  
  193.         hItems = (hItemList) (theDialogPtr->items);
  194.         num_items = (*hItems)->dlgMaxIndex + 1;
  195.  
  196.         draft_title = "Draft";
  197.         better_title = "Faster";
  198.         best_title = "Best";
  199.         draft_selected = false;
  200.         
  201.         for (i = 1; i <= num_items; i++ )
  202.             {
  203.                 /* get the item */
  204.                 
  205.                 item_no = i;
  206.                 
  207.                 GetDItem( (DialogPtr) theDialogPtr, item_no, &the_type, &the_item, &the_box);
  208.                 
  209.                 /* used to bit and with 7F */
  210.                 the_and_type = the_type & 0X7F;
  211.                 switch  ( the_and_type )    { 
  212.                     /* is it a radio button */
  213.                         case    ctrlItem + radCtrl:
  214.                                 getctitle( (ControlHandle) the_item, the_title);
  215.                                 if ((*the_title) == (*draft_title))
  216.                                     {
  217.                                         draft_value = GetCtlValue((ControlHandle) the_item);
  218.                                         if ( draft_value > 0 ) 
  219.                                             {
  220.                                                 draft_selected = true;
  221.                                                 draft_value = 0;
  222.                                                 SetCtlValue((ControlHandle) the_item, draft_value);
  223.                                             }
  224.                                         HiliteControl( (ControlHandle) the_item, 255);
  225.     /*    comment the previous line and uncomment */
  226.     /*    the next two lines of code to see the */
  227.     /*    difference between disabling item */
  228.     /*    and inactivating control */
  229.                                         
  230.                                     /* the_and_type = the_type | 0X80; */
  231.                                     /* SetDItem( (DialogPtr) theDialogPtr, item_no, the_and_type, the_item, &the_box); */
  232.                                          draft_item_no = item_no;
  233.                                      }
  234.                                 else
  235.                                     if ((*the_title) == (*better_title) ) 
  236.                                          better_item_no = item_no;
  237.                                     else
  238.                                         if ((*the_title) == (*best_title) ) 
  239.                                          best_item_no = item_no;
  240.                                     
  241.                             break;
  242.                     }    /* end of switch */
  243.                 
  244.         } /* of for loop */
  245.                                 
  246.     } /*  of disabling the printing in draft mode */
  247.         
  248. /*-------------------------------------------- */
  249.  
  250. pascal TPPrDlg MyJobDlgInit(hPrint)
  251.     
  252. THPrint    hPrint;
  253.         
  254.     {
  255.         /* call PrJobInit to get pointer to the */            
  256.         /* invisible job dialog */
  257.         PrtJobDialog = PrJobInit(hPrint);
  258.         if (PrError() != noErr)
  259.             return nil;
  260.  
  261.         /* set up the filter function */
  262.         PrtJobDialog->pFltrProc = (ModalFilterProcPtr)&Net_filter;
  263.             
  264.         /* disable the draft mod now */
  265.             
  266.         DisableDraftMode(PrtJobDialog);
  267.  
  268.         /* PrDlgMain expects pointer the modified */
  269.         /* dialog to be returned.... */
  270.             
  271.         return ( PrtJobDialog );
  272.             
  273.     }    /* myJobDlgInit */
  274.  
  275. /*--------------------------------------------*/
  276.  
  277. OSErr DoPrintDialog()
  278.  
  279.     {
  280.         hPrintRec = (THPrint) NewHandle(sizeof(TPrint));
  281.         PrintDefault(hPrintRec);
  282.         PrValidate(hPrintRec);
  283.         if (PrError() != noErr)
  284.             return PrError();
  285.  
  286.          /* Here’s the line that does it all! */
  287.         if (!PrDlgMain(hPrintRec,&MyJobDlgInit))
  288.             return 2;
  289.  
  290.         if (PrError() != noErr)
  291.             return PrError();
  292.  
  293.         /* that’s all for now  */
  294. }
  295.